<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>会员充值</el-breadcrumb-item>
        <el-breadcrumb-item>提现配置</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>

    <basic-container>
      <!-- <template>
				<div style="margin: 20px;">
					<span style="margin-right: 40px;">活动名称：用家乡话秀出你的新年flag </span>
					<span>活动时间：2021.02.08—2021.02.18</span>
				</div>
			</template> -->
      <avue-crud
        :table-loading="loading"
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-del="rowDel"
        @row-save="saveList"
        @search-reset="from = {}"
      >
        <template slot="last" slot-scope="scope">
          {{ scope.row.edit_time }}
          <span style="margin-left: 10px">{{ scope.row.edit_admin_name }}</span>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>


<script>
// import {
// 	handleExcelCat
// } from "@/api/exportCommon";
import { common } from "@/api/cat/httpRequest";
// import {
// 	catUrl
// } from "@/config/env";
import { appConfigWithdrawal as baseURL } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      loading: false,
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        orderByList: "", //'stats_date&DESC'
      },
      option: {
        addBtn: true,
        // selection: true,
        border: true,
        menu: true,
        column: [
          {
            label: "版本号",
            prop: "app_version",
            type: "input",

            search: true,
          },
          {
            label: "体现金额",
            prop: "price",
            type: "input",
            search: false,
          },
          {
            label: "排序",
            prop: "sort",
            type: "input",
            search: false,
          },
          {
            label: "最后操作信息", //edit_admin_name edit_time
            prop: "last",
            type: "input",
            slot: true,
            search: false,
            addDisplay: false,
            editDisplay: false,
            addDisabled: false,
          },
        ],
      },
    };
  },
  // async created() {
  // 	let data = await common(`${appConfigWithdrawal.getListByLeave}/2`)
  // 	if (data.code == 1) {
  // 		this.option.column[4].dicData = data.data;
  // 	}
  // },
  methods: {
    //数据导出
    async handleExcel() {
      this.loading = true;
      //处理搜索条件
      let params = { ...this.$refs.crud.searchForm };
      this.default.orderByList = "stats_date&DESC";
      this.default.orderByList = this.default.orderByList + params.order;
      delete params.order;
      // if (params.statistics_date_search && params.statistics_date_search.length > 0) {
      // 	params.statistics_date = `!<>!${params.statistics_date_search}`
      // }
      // delete params.statistics_date_search;

      //调用导出接口
      handleExcelCat(
        this.$export,
        baseURL.pageAndParam,
        { ...params, ...this.default },
        "新年活动数据统计",
        this.page.total,
        [...this.option.column]
      );
      this.loading = false;
    },
	//修改
	 async rowUpdate(row, index, done, loading) {
   
      let data = await common(
		   baseURL.update,
		   row,
		   null,
		   'POST'
	  );
	  this.loading = false
      this.getList();
      done();
    },
    //删除
    rowDel(row, done, loading) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        let response = await common(
          baseURL.delete,
         {id:row.id},
          {},
          // this.page,
          "GET"
        );
		if(response.code==1){
			this.getList()
		}
      });
    },
    // 新增保存
    async saveList(row, done, loading) {
      this.params = row;
      let response = await common(
        baseURL.save,
        {
          ...this.params,
          // ...this.default
        },
        {},
        // this.page,
        "POST"
      );
      if (response.code == 1) {
        this.params = {};
        this.getList();
      }
      this.loading = false;
      done();
    },
    //搜索
    searchChange(params, done) {
      this.params = params;
      this.getList();
      this.loading = false;
      if (done) done();
    },
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      // /orangecat/appConfigWithdrawal/pageAndParam
      let response = await common(
        baseURL.pageAndParam,
        {
          ...this.params,
          // ...this.default
        },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    } /**刷新 */,
    refreshChange() {
      this.getList();
    },
  },
};
</script>
